package org.example;

/**
 * ClassName: WuDaProxy
 * Package: org.example
 * Description: 代理类 Proxy
 *
 * @Author wanghao
 * @Create 2024-07-08 8:45
 * @Version 1.0
 */
public class WuDaProxy implements ISale {

    private WuDa target;


    public WuDaProxy(WuDa target) {
        this.target = target;
    }

    /**
     * 在当前的卖烧饼方法中，有原始的卖烧饼方法和额外操作，这两者组合的过程我们称之为织入（weave）
     */
    @Override
    public void saleShaoBing() {

        target.saleShaoBing();
        song();  // 后置增强
    }

    @Override
    public void saleHotDog() {

        song(); // 前置增强
        target.saleHotDog();

    }

    @Override
    public void saleMilkTea() {
        try {
            target.saleMilkTea();
        } catch (Exception e) {
            e.printStackTrace();
            song();  //抛异常时增强
        }
    }

    @Override
    public void saleJuice() {

        target.saleJuice();
    }

    // 额外操作（追加操作） - 增强：Advice
    private void song() {
        System.out.println("送大麦茶");
    }
}
